package xml.sax;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class JSONDemo {
    public static void main(String[] args) {
        List<Book> list=new ArrayList<>();
        for(int i=1;i<=10;i++){
            Book b=new Book(i,"java"+i+"大全",100,5,"很好的一本书");
            list.add(b);
        }
        Object o = JSON.toJSON(list);
        System.out.println(o);
        String str="[{\"name\":\"java1大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":1},{\"name\":\"java2大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":2},{\"name\":\"java3大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":3},{\"name\":\"java4大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":4},{\"name\":\"java5大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":5},{\"name\":\"java6大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":6},{\"name\":\"java7大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":7},{\"name\":\"java8大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":8},{\"name\":\"java9大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":9},{\"name\":\"java10大全\",\"description\":\"很好的一本书\",\"difficult\":5,\"time\":100,\"order\":10}]";
        List<Book> books = JSON.parseArray(str, Book.class);
        for(Book b:books){
            System.out.println(b);
        }
    }
}
